//
// Created by WYX on 2024/9/4.
//
#include <iostream>
#include <string>
#include <cmath>
#include <vector>

std::string multiply(const std::string& num1, const std::string& num2) {
    int n1 = num1.size();
    int n2 = num2.size();
    std::vector<int> result(n1 + n2, 0);

    for (int i = n1 - 1; i >= 0; i--) {
        for (int j = n2 - 1; j >= 0; j--) {
            int mul = (num1[i] - '0') * (num2[j] - '0');
            int sum = result[i + j + 1] + mul;
            result[i + j + 1] = sum % 10;
            result[i + j] += sum / 10;
        }
    }

    std::string s;
    bool leading_zero = true;
    for (int digit : result) {
        if (digit != 0 || !leading_zero) {
            s.push_back(digit + '0');
            leading_zero = false;
        }
    }

    return s.empty() ? "0" : s;
}

std::string power_of_two(int exponent) {
    std::string result = "1";
    std::string base = "2";

    while (exponent > 0) {
        if (exponent & 1) {
            result = multiply(result, base);
        }
        base = multiply(base, base);
        exponent >>= 1;
    }

    return result;
}

int main() {
    std::string result = power_of_two(1023);
    std::cout << "2^1023 = " << result << std::endl;
    std::string s=std::to_string(pow(2,1023)).substr(0,result.length());
    std::cout<<s<<std::endl;
    if(s==result)
        std::cout << "Number of digits: " << result.length() << std::endl;
    else
    {
        std::cout << "Error" << std::endl;
        std::cout<<result.length()<<std::endl;
        std::cout<<s.length()<<std::endl;
    }
    return 0;
}